package com.ydgk.servlet;

import com.alibaba.fastjson.JSON;
import com.ydgk.dao.BookDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;

@WebServlet(name = "DeleteBookByIdServlet", urlPatterns = "/DeleteBookByIdServlet.action")
public class DeleteBookByIdServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String bid = request.getParameter("bid");

        BookDao bookDao= new BookDao() ;
        int i=bookDao.deleteById(Integer.parseInt(bid));
        PrintWriter out = response.getWriter();
        HashMap map = new HashMap();
        if(i > 0){
            map.put("flag" , true);
        }else{
            map.put("flag" , false);
        }

        out.print(JSON.toJSONString(map));
    }


}
